<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>ES6新增语法</title>
	</head>
	<body>
		<script>
//			//1. const 常量
//			const pi = 3.14
//			pi = 3 //报错：Assignment to constant variable.
//			
//			//2. let 块级作用域
//			{
//				var a = 3
//				let b = 4
//			}
//			console.log(a) // 3
//			console.log(b) // 报错：b is not defined
			
			//3. 解构赋值
			//- 数组的解构赋值
			let arr = ['三国演义','红楼梦','西游记','水浒传']
			
			let [b1,b2,b3] = arr
			
			console.log(b2) //红楼梦
			//- 对象的解构赋值
			let obj = {
				name:'kk',
				age:13,
				gender:'famale'
			}
			let {name,age,gender} = obj
			console.log(age) // 13
			
			//- 函数参数的解构赋值，传一个对象作为参数,实际是对一个对象做了解构赋值
			function introduce({name,age,gender}){
//				let {name,age,gender} = person
				console.log('我叫'+name+',今年'+age+'岁了。')
			}
			introduce(obj)
			//- 字符串的解构赋值
			const [a, b, c, d, e] = 'hello'
			let {length} = 'hello'
			console.log(length) // 5
			//- 数值和布尔值的解构赋值
			let {toString:num} = 123
			num === Number.prototype.toString() // true
			let {toString:boo} = true
			boo === Boolean.prototype.toString() // true
			
			//4. 运算符
			let o = undefined
			let p = o||{name:'小明'}
			console.log(p) //{name:'小明'}
			
			//5.箭头函数  参数=>返回值
			let plus = a => a*a
			console.log(plus(5))
			//如果函数的代码超过一行，则必须用{}括起来
			let compare = (a,b) => {
				console.log(a>b?'大于':'小于')
			}
			compare(3,4)
			
		</script>
	</body>
</html>
